<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单</title>
    <!--引入vue.js库-->
    <script src="/js/vue.js"></script>
    <!-- element-ui引入样式 展示数据的-->
    <link rel="stylesheet" href="/css/index.css">
    <!-- element-ui引入组件库 -->
    <script src="/js/index.js"></script>
    <!--引入axios库  从后端获取数据-->
    <!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
    <script src="/js/axios.min.js"></script>
    <!--<script src="/js/axios.min.js"></script>-->
</head>
<body>
<div id="app">
    <el-row>
        <el-col :span="4">
            <el-input v-model="searchForm.scenicname" placeholder="请输入景区名称"></el-input>
        </el-col>
        <el-col :span="4">
            <el-input v-model="searchForm.ticketname" placeholder="请输入门票名称"></el-input>
        </el-col>

        <el-col :span="2">
            <el-button type="success" icon="el-icon-search" @click="search">搜索</el-button>
        </el-col>
        <el-col :span="2">
            <el-button type="primary" icon="el-icon-plus" @click="handleAdd">添加</el-button>
        </el-col>
        <el-col :span="2"> <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新</el-button></el-col>
    </el-row>
    <el-table :data="tableData" border style="width: 100%">
<!--        <el-table-column fixed width="100" prop="orderid" label="订单id" min-height="100px"></el-table-column>-->
<!--        &lt;!&ndash;        <el-table-column width="200" prop="deptId" label="部门ID"></el-table-column>&ndash;&gt;-->
<!--        <el-table-column  prop="scenicid" label="景区id" min-height="100px"></el-table-column>-->
        <el-table-column width="300"  prop="orderno" label="订单号" min-height="160px"></el-table-column>
        <el-table-column width="210" prop="ywrq" label="游玩日期" min-height="160px"></el-table-column>
        <el-table-column width="210"  prop="zczfsj" label="最迟取票日期" min-height="160px"></el-table-column>
        <el-table-column  width="210" prop="zcqprq" label="最迟取票日期" min-height="160px"></el-table-column>
        <el-table-column  prop="ptype" label="支付方式" min-height="160px">
            <template slot-scope="scope">
                <div v-if="scope.row.ptype == 1">景区支付</div>
                <div v-else>线上支付</div>
            </template>
        </el-table-column>
<!--        <el-table-column  prop="ticketid" label="门票id" min-height="160px" ></el-table-column>-->
        <el-table-column  prop="scenicname" label="景区名称" min-height="160px"></el-table-column>
        <el-table-column  prop="ticketname" label="门票名称" min-height="160px"></el-table-column>
        <el-table-column width="210" prop="zcdpsj" label="最迟订票时间" min-height="160px"></el-table-column>
        <el-table-column  prop="price" label="单价" min-height="160px"></el-table-column>
        <el-table-column  prop="tcount" label="总票数" min-height="160px"></el-table-column>
        <el-table-column  prop="tprice" label="总票价" min-height="160px"> </el-table-column>
        <el-table-column  prop="qprname" label="取票人名字" min-height="160px"></el-table-column>
        <el-table-column  prop="qprsj" label="取票人时间" min-height="160px"></el-table-column>
<!--        <el-table-column  prop="userid" label="用户id" min-height="160px"></el-table-column>-->
<!--        <el-table-column  prop="codeid" label="状态码表id" min-height="160px"></el-table-column>-->
        <el-table-column  prop="state" label="状态" >
            <template slot-scope="scope">
                <div v-if="scope.row.state == 11">待付款</div>
                <div v-if="scope.row.state == 12">已付款</div>
                <div v-if="scope.row.state == 13">已取票</div>
                <div v-if="scope.row.state == 14">待审核</div>
                <div v-if="scope.row.state == 15">待退款</div>
                <div v-if="scope.row.state == 16">待付款退单结束</div>
                <div v-if="scope.row.state == 17">付款超时结束</div>
                <div v-if="scope.row.state == 18">预定成功退单结束</div>
                <div v-if="scope.row.state == 19">退款审核不通过结束</div>
                <div v-if="scope.row.state == 20">退款完成结束</div>
                <div v-if="scope.row.state == 21">取票超时结束</div>
                <div v-if="scope.row.state == 22">退票结束</div>
                <div v-if="scope.row.state == 27">点评超时结束</div>
                <div v-if="scope.row.state == 28">点评完成结束</div>
            </template>
        </el-table-column>
        <el-table-column width="210"  prop="ordertime" label="下单时间" min-height="160px"></el-table-column>
        <el-table-column fixed="right" width="200" label="操作" width="140">
            <template slot-scope="scope">
                <el-button
                        type="primary"
                        @click="handleEdit(scope.$index, scope.row)">编辑
                </el-button>
                <el-button type="danger" @click="TsDelete(scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
    <!--    分页功能-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[6, 12, 15, 60]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>
    <!--    添加修改弹窗-->
    <el-dialog :title="title" :visible.sync="dialogFormVisible" >
        <el-form :model="form" :rules="rules" ref="form">
            <el-form-item label="景点名称" :label-width="formLabelWidth" prop="scenicname">
                <el-input v-model="form.scenicname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="门票名称" :label-width="formLabelWidth" prop="ticketname">
                <el-input v-model="form.ticketname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="取票人名字" :label-width="formLabelWidth" prop="qprname">
                <el-input v-model="form.qprname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="取票人时间" :label-width="formLabelWidth" prop="qprsj">
                <el-input v-model="form.qprsj" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="状态" :label-width="formLabelWidth"  prop="state">
                <el-select v-model="form.state" placeholder="订单状态" >
                    <el-option label="待付款" value="11"></el-option>
                    <el-option label="已付款" value="12"></el-option>
                    <el-option label="已取票" value="13"></el-option>
                    <el-option label="待审核" value="14"></el-option>
                    <el-option label="待退款" value="15"></el-option>
                    <el-option label="待付款退单结束" value="16"></el-option>
                    <el-option label="付款超时结束" value="17"></el-option>
                    <el-option label="预定成功退单结束" value="18"></el-option>
                    <el-option label="退款审核不通过结束" value="19"></el-option>
                    <el-option label="退款完成结束" value="10"></el-option>
                    <el-option label="取票超时结束" value="21"></el-option>
                    <el-option label="退票结束" value="22"></el-option>
                    <el-option label="点评超市结束" value="27"></el-option>
                    <el-option label="点评完成结束" value="28"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addOrUpdate">确 定</el-button>
        </div>
    </el-dialog>
</div>
<script>
    var vue=new Vue({
        el: "#app",
        data() {
            return {
                tableData: [],
                currentPage: 1,//
                pageSize: 6,//
                total: 100,//分页总数量
                searchForm: {scenicname: '',ticketname:''},
                dialogFormVisible: false,
                title: '添加',
                formLabelWidth: '120px',
                form: {
                    scenicname:'',
                    ticketname:'',
                    pqrname:'',
                    pqrsj:'',
                    state:'',
                },
                rules:{
                    scenicname: [
                        { required: true, message: '请输入景点名称', trigger: 'blur' },
                    ],
                    ticketname: [
                        { required: true, message: '请输入门票名称', trigger: 'blur' },
                    ],

                }
            }
        },
        created: function () {
            this.loadData();
        },
        methods: {
            loadData() {
                var _this = this;
                axios.post("/tsb/queryPage", {
                    "pageNo": this.currentPage, "pageSize": this.pageSize,
                    "data":{
                        "scenicname":this.searchForm.scenicname,"ticketname":this.searchForm.ticketname
                    }
                })
                    .then(function (response) {
                        console.log(response);
                        if (response.data.code == 200) {
                            _this.tableData = response.data.data.list;
                            _this.total = response.data.data.total;
                        }
                    }).catch(function (error) {
                    console.log(error);
                });
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.pageSize = val;
                this.loadData();
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.currentPage = val;
                this.loadData();
            },
            search() {
                this.loadData();
            },
            handleEdit(index, row) {
                console.log(index, row);
                this.dialogFormVisible = true;
                this.title = '用户更新';
                this.form = row;
            },
            handleAdd() {
                this.dialogFormVisible = true;
                this.title = '用户添加';
                this.form = {}
            },
            handleClose(done) {
                this.$confirm('确认关闭？')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => {
                    });
            },
            TsDelete(row) {
                this.$confirm('此操作将删除该用户, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }).then(() => {
                    var _this = this;
                    axios.post("/tsb/TsbDelete/" + row.orderid)
                        .then(function (response) {
                            console.log(response);
                            if (response.data.code == 200) {
                                _this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                                _this.dialogFormVisible = false;
                                _this.loadData();
                            } else {
                                _this.$message("操作失败")
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                        });
                })
            },
            //刷新
            refresh() {
                //原始js重新请求
                location.reload();
            },
            addOrUpdate() {
                var uri = "/tsb/TsbAdd";
                if (this.title == '用户更新') {
                    uri = "/tsb/TsbUpdate";
                }
                var _this = this;
                axios.post(uri, this.form)
                    .then(function (response) {
                        console.log(response);
                        if (response.data.code == 200) {
                            _this.$message({
                                message: '操作成功',
                                type: 'success'
                            });
                            _this.dialogFormVisible = false;
                            _this.loadData();
                        } else {
                            _this.$message("操作失败")
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            }
        }
    })
</script>

</body>
</html>